package com.md.common.exception;

import org.apache.commons.lang3.builder.ToStringBuilder;

/**
 * 功能描述：业务异常类父类
 *
 * @author lujianping@oak168.com
 * @version 1.0
 * @date 2018-6-14 11:51
 * @since JDK 1.8
 */
public class BaseBizException extends RuntimeException{
    /**
     * 
     */
    private static final long serialVersionUID = 3017310971089978264L;
    protected int code;//异常错误码
    protected String message;//异常信息
    public int getCode() {
        return code;
    }
    public void setCode(int code) {
        this.code = code;
    }
    public String getMessage() {
        return message;
    }
    public void setMessage(String message) {
        this.message = message;
    }
    /**
     * 
     */
    public BaseBizException() {
        super();
    }
    /**
     * 
     * @param code 异常错误码
     * @param message 异常信息
     * @param objects 异常信息中补充对象信息
     */
    public BaseBizException(int code, String message,Object...objects) {
        super(String.format(message, objects));
        this.code = code;
        this.message = String.format(message, objects);
    }
    /**
     * 
     * @param code 异常错误码
     * @param cause 异常堆栈
     * @param message 异常信息
     * @param objects 异常信息中补充对象信息
     */
    public BaseBizException(int code, Throwable cause, String message,Object...objects) {
        super(String.format(message, objects),cause);
        this.code = code;
        this.message = String.format(message, objects);
    }
    /**
     * 
     * @param cause 异常堆栈
     * @param message 异常信息
     * @param objects 异常信息中补充对象信息
     */
    public BaseBizException(Throwable cause, String message,Object...objects) {
        super(String.format(message, objects),cause);
        this.message = String.format(message, objects);
    }
    /**
     * 
     * @param code 异常错误码
     * @param objects 异常信息中补充对象信息
     */
    public BaseBizException(int code, Object...objects) {
        super(String.format(new BaseErrorCode().getErrorMsg(code), objects));
        this.code = code;
        this.message = String.format(new BaseErrorCode().getErrorMsg(code), objects);
    }
    public BaseBizException(String message) {
        super(message);
        this.message = message;
    }
    /**
     * 
     * @param message 异常信息
     * @param cause 异常堆栈
     */
    public BaseBizException(String message, Throwable cause) {
        super(message,cause);
        this.message = message;
    }

    /**
     * 
     * @param code 错误码
     * @param cause 异常堆栈
     */
    public BaseBizException(int code, Throwable cause) {
        super(String.format(new BaseErrorCode().getErrorMsg(code)), cause);
        this.code = code;
        this.message = new BaseErrorCode().getErrorMsg(code);
    }

    /**
     * @param cause 异常堆栈
     */
    public BaseBizException(Throwable cause) {
        super(cause);
    }
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
    
}
